﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using KF.Common;


namespace KF.DHL.DAL
{
    public class ZoneInfo
    {
        public List<KF.DHLModel.ZoneInfo> GetZoneInfo()
        {
            DataSet ds = new DataSet();
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select * from CountryZoneInfo ");


            try
            {
                Database db = DatabaseFactory.CreateDatabase(DBConfig.Pricing);
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());


                ds = db.ExecuteDataSet(dbCommand);

                List<KF.DHLModel.ZoneInfo> infos = new List<DHLModel.ZoneInfo>();


                KF.DHLModel.ZoneInfo info;

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    info = new DHLModel.ZoneInfo();
                    info.ID = Convert.ToInt32(dr["ID"]);
                    info.NameEN = dr["NameEN"].ToString();
                    info.NameS = dr["NameSimplified"].ToString();
                    info.NameI = dr["NameTraditional"].ToString();
                    info.Zone = Convert.ToInt32(dr["Zone"]);
                    infos.Add(info);
                }

                return infos;


            }
            catch (System.Exception ex)
            {
                LogHelper.DebugHelper.WriteLog(ex.ToString(), LogHelper.ExceptionHelper.ExceptionLevel.Exception);
                return null;
            }
        }
    }
}
